<!DOCTYPE html>
<html lang="zh-CN">
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
		<title>分数填写脚本</title>
		<script type="text/javascript" src="../../commonFragment/header.js"></script>
		<script type="text/javascript" src="../../commonFragment/nojs.header.js"></script>
		<script>
			$(function(){
				$("button.generator").on("click", function(){
					if(!$("form").valid()){
						return;
					}
					var url = "/student/zblStudentScore/scoreMap";
					var data = {
						clazz: $("#clazz").val(),
						term: $("#term").val()
					}
					$request.get(url,{data: data}, function(result){
						var data = result.data;
						$.alert(result.msg,"总数");
						var dataDefine = 'var data = ' + JSON.stringify(data) + ";\n";
						var js = $("#t2").val();
						 $("#t1").val(dataDefine + js);
					})
				})
			});
			
		</script>
	</head>
	<body>
		<div class="container-fluid p-t-15">
			<div class="row">
				<div class="col-lg-12">
					<div class="card">
						<div class="well">
							<ul class="list-group">
								<li class="list-group-item active">操作办法:</li>
							    <li class="list-group-item">1. 选择班级和学期后点击生成脚本</li>
							    <li class="list-group-item">2. 全选并复制脚本</li>
							    <li class="list-group-item">3. 进入录入成绩页面</li>
							    <li class="list-group-item">4. 右击某个要录入成绩的输入框,选择"检查"</li>
							    <li class="list-group-item">5. 在打开的页面,选择"Console"页签</li>
								<li class="list-group-item">6. 粘贴脚本,并点击键盘"Enter"按钮</li>
								<li class="list-group-item">7. 查看页面成绩是否正确录入(保证录入本系统的数据的正确性)</li>
							</ul>
						</div>
						<div class="card-body">
							<form class="form-horizontal validate" role="form">
								<div class="form-group">
									<label for="year" class="col-sm-2 control-label">学期*</label>
									<div class="col-sm-8 ">
										<select class="form-control" id="term" name="term" data-rule-required="true" data-url="/student/zblStudentScore/termSelect">
											<option value="">--请选择学期--</option>
										</select>

									</div>
									<div class="col-sm-2  help-inline form-control-static"></div>
								</div>
								<div class="form-group">
									<label for="clazz" class="col-sm-2 control-label">班级*</label>
									<div class="col-sm-8 ">
										<select class="form-control" id="clazz" name="clazz" data-rule-required="true" data-url="/student/zblStudentBase/clazzSelect">
											<option value="">--请选择班级--</option>
										</select>
									</div>
									<div class="col-sm-2  help-inline form-control-static"></div>
								</div>

								<div class="form-group clearfix">
									<div class="col-sm-offset-3 col-sm-9">
										<button type="button" class="btn btn-primary generator">
											<i class="glyphicon glyphicon-ok"></i> 生成脚本
										</button>
										<button type="button" class="btn btn-info action-close-tab">
											<i class="glyphicon glyphicon-repeat"></i> 返回
										</button>
									</div>
								</div>
							</form>
						</div>
						<div class="well">
							<textarea style="width: 100%;" rows="50" id="t1">
							</textarea>
							<textarea style="width: 100%;display: none;" rows="50" id="t2">
								function getChidren(parent, tagName) {
									var res = [];
									var chidrens = parent.children;
									for (var i = 0; i < chidrens.length; i++) {
										var c = chidrens[i];
										if (c.tagName.toLowerCase() == tagName.toLowerCase()) {
											res.push(c);
										}
									}
									return res;
								}
								
								function fill() {
								
									var table = document.querySelectorAll("table")[2];
									var tbody = table.children[0];
									var trs = tbody.children;
									var len = trs.length;
									for (var j = 0; j < len; j++) {
										var tr = trs[j];
										var tds = getChidren(tr, "td");
										var num = "";
										var score = {
											dailyScore: 0,
											practiceScore: 0,
											taskScore: 0,
											finalScore: 0
										};
										for (var i = 0; i < tds.length; i++) {
											var td = tds[i];
											
											switch (i) {
												case 1: //学号
													num = td.innerText;
													var s = data[num.trim()];
													if (s) {
														score = s;
													}
													break;
												case 5: //平时
													getChidren(td, "input")[0].value = score.dailyScore;
													break
												case 7: //末考
													getChidren(td, "input")[0].value = score.taskScore;
													break;
												case 8: //实训
													getChidren(td, "input")[0].value = score.practiceScore;
													break;
													/* case 9://综合
														getChidren(td,"input")[0].value= score.finalScore;
														break;	 */
												default:
													break;
											}
										}
									}
								}
								fill();
								
							</textarea>
						</div>
					</div>

				</div>
			</div>

		</div>
	</body>
</html>
